package com.api.shopapi.mapper;

import com.api.shopapi.entity.NursingType;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface NursingTypeMapper {

    @Select("select  * from  nursing_type where InstitutionCode=#{institutionCode} and Status=0 order by sort desc ")
    List<NursingType> getList(@Param("institutionCode") String institutionCode);

    @Select("select  * from  nursing_type where institutionCode=#{institutionCode} order by sort desc")
    List<NursingType> getListNursingType(@Param("institutionCode") String institutionCode);

    @Insert("insert into nursing_type " +
            "(NursingTypeCode,Name,Sort,Status,StaffCode,InstitutionCode) " +
            "values (#{nursingType.nursingTypeCode} ,#{nursingType.name} ,#{nursingType.sort} ,#{nursingType.status} ,#{nursingType.staffCode} ,#{nursingType.institutionCode} )")
    int insert(@Param("nursingType") NursingType nursingType);

    @Update("update  nursing_type set name=#{nursingType.name} ,sort=#{nursingType.sort} ,status=#{nursingType.status} ,staffCode=#{nursingType.staffCode}  where nursingTypeCode=#{nursingType.nursingTypeCode} ")
    int updateByNursingTypeCode(@Param("nursingType") NursingType nursingType);

    @Delete("delete from nursing_type where nursingTypeCode =#{nursingTypeCode} ")
    int deleteByNursingTypeCode(@Param("nursingTypeCode") String nursingTypeCode);

    @Select("select * from nursing_type where nursingTypeCode=#{nursingTypeCode} limit 1")
    NursingType getByNursingTypeCode(@Param("nursingTypeCode") String nursingTypeCode);

    @Select("select * from nursing_type where name=#{name} and InstitutionCode=#{institutionCode}")
    NursingType getByNameAndInstitutionCode(@Param("name") String name, @Param("institutionCode") String institutionCode);



    @Select("select  * from  nursing_type" +
            " where" +
            " institutionCode in (select institutionCode from institution where governmentCode=#{governmentCode})" +
            " order by sort desc")
    List<NursingType> listByGovCode(@Param("governmentCode") String governmentCode);


}
